package bean;

import java.util.*;

public class list_paixu {
    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        scanner.nextLine();
        String a[][] = new String[n][];
        for (int i = 0; i < n; i++) {
            String s = scanner.nextLine();
            a[i] = s.split(" ");

        }
        HashMap<String, Double> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if (!map.containsKey(a[i][0])) {
                Double d = Double.parseDouble(a[i][2]);
                Integer i1 = Integer.valueOf(a[i][1]);
                map.put(a[i][0], i1 * d);
            } else {
                Double d = Double.parseDouble(a[i][2]);
                Integer i1 = Integer.valueOf(a[i][1]);
                map.put(a[i][0], i1 * d + map.get(a[i][0]));
            }
        }
        List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(map.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
            //升序排序
            public int compare(Map.Entry<String, Double> o1,
                               Map.Entry<String, Double> o2) {
                return o2.getValue().compareTo(o1.getValue());
            }

        });
        for (Map.Entry<String, Double> mapping : list) {
            System.out.println(mapping.getKey() + ":" + mapping.getValue());
        }
        Iterator iterator = map.entrySet().iterator();
        /*while (iterator.hasNext()){
            Map.Entry map1= (Map.Entry) iterator.next();
            System.out.println(map1.getKey()+"  "+map1.getValue());
        }*/
    }
}
